package com.company.test16;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Created by Administrator on 2016.8.4.
 */
public class Test1612 extends JFrame{
    public Test1612(){
        this.add(new ArcsPanel());
    }

    public static void main(String[] args){
        JFrame frame=new Test1612();

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocationRelativeTo(null);
        frame.setSize(200,200);
        frame.setTitle("小风扇");
        frame.setVisible(true);
    }

    class ArcsPanel extends JPanel{
        private int angle;

        public ArcsPanel(){
            angle=0;
            Timer timer=new Timer(100,new TimerLinst());

            timer.start();
        }

        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);

            int xCenter=getWidth()/2;
            int yCenter=getHeight()/2;

            int radius=(int)(Math.min(getWidth(),getHeight())*0.4);

            int x=xCenter-radius;
            int y=yCenter-radius;

            g.fillArc(x,y,2*radius,2*radius,angle,30);
            g.fillArc(x,y,2*radius,2*radius,angle+90,30);
            g.fillArc(x,y,2*radius,2*radius,angle+180,30);
            g.fillArc(x,y,2*radius,2*radius,angle+270,30);
        }

        class TimerLinst implements ActionListener{

            @Override
            public void actionPerformed(ActionEvent e) {
                if (angle==360){
                    angle=0;
                }

                angle=angle+30;

                repaint();
            }
        }
    }
}
